package com.market.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "flyer")
public class Flyer extends BaseObject {

	@Override
	public boolean equalsId(Object o) {
		if ((o instanceof Flyer) && ((Flyer) o).getId().equals(this.id)) {
			return true;
		}

		return false;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id = 0L;
	@Column(length = 200)
	private String title;
	@Column(length = 200)
	private String chineseTitle;
	@Column(length = 200)
	private String frenchTitle;
	@Column(length = 200)
	private String validDate;
	@Column(length = 200)
	private String chineseValidDate;
	@Column(length = 200)
	private String frenchValideDate;
	@Column(length = 1000)
	private String description;
	@Column(length = 1000)
	private String chineseDescription;
	@Column(length = 1000)
	private String frenchDescription;
	@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
	@Temporal(TemporalType.TIMESTAMP)
	private Date createdDate;
	@ManyToMany(fetch=FetchType.LAZY)	
	private List<Product> products = new ArrayList<Product>();
	

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getChineseTitle() {
		return chineseTitle;
	}

	public void setChineseTitle(String chineseTitle) {
		this.chineseTitle = chineseTitle;
	}

	public String getFrenchTitle() {
		return frenchTitle;
	}

	public void setFrenchTitle(String frenchTitle) {
		this.frenchTitle = frenchTitle;
	}

	public String getValidDate() {
		return validDate;
	}

	public void setValidDate(String validDate) {
		this.validDate = validDate;
	}

	public String getChineseValidDate() {
		return chineseValidDate;
	}

	public void setChineseValidDate(String chineseValidDate) {
		this.chineseValidDate = chineseValidDate;
	}

	public String getFrenchValideDate() {
		return frenchValideDate;
	}

	public void setFrenchValideDate(String frenchValideDate) {
		this.frenchValideDate = frenchValideDate;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getChineseDescription() {
		return chineseDescription;
	}

	public void setChineseDescription(String chineseDescription) {
		this.chineseDescription = chineseDescription;
	}

	public String getFrenchDescription() {
		return frenchDescription;
	}

	public void setFrenchDescription(String frenchDescription) {
		this.frenchDescription = frenchDescription;
	}

	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	@Override
	public String toString() {
		return "Flyer [id=" + id + ", title=" + title + ", chineseTitle="
				+ chineseTitle + ", frenchTitle=" + frenchTitle
				+ ", validDate=" + validDate + ", chineseValidDate="
				+ chineseValidDate + ", frenchValideDate=" + frenchValideDate
				+ ", description=" + description + ", chineseDescription="
				+ chineseDescription + ", frenchDescription="
				+ frenchDescription + ", createdDate=" + createdDate + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime
				* result
				+ ((chineseDescription == null) ? 0 : chineseDescription
						.hashCode());
		result = prime * result
				+ ((chineseTitle == null) ? 0 : chineseTitle.hashCode());
		result = prime
				* result
				+ ((chineseValidDate == null) ? 0 : chineseValidDate.hashCode());
		result = prime * result
				+ ((createdDate == null) ? 0 : createdDate.hashCode());
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		result = prime
				* result
				+ ((frenchDescription == null) ? 0 : frenchDescription
						.hashCode());
		result = prime * result
				+ ((frenchTitle == null) ? 0 : frenchTitle.hashCode());
		result = prime
				* result
				+ ((frenchValideDate == null) ? 0 : frenchValideDate.hashCode());
		result = prime * result + ((title == null) ? 0 : title.hashCode());
		result = prime * result
				+ ((validDate == null) ? 0 : validDate.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Flyer other = (Flyer) obj;
		if (chineseDescription == null) {
			if (other.chineseDescription != null)
				return false;
		} else if (!chineseDescription.equals(other.chineseDescription))
			return false;
		if (chineseTitle == null) {
			if (other.chineseTitle != null)
				return false;
		} else if (!chineseTitle.equals(other.chineseTitle))
			return false;
		if (chineseValidDate == null) {
			if (other.chineseValidDate != null)
				return false;
		} else if (!chineseValidDate.equals(other.chineseValidDate))
			return false;
		if (createdDate == null) {
			if (other.createdDate != null)
				return false;
		} else if (!createdDate.equals(other.createdDate))
			return false;
		if (description == null) {
			if (other.description != null)
				return false;
		} else if (!description.equals(other.description))
			return false;
		if (frenchDescription == null) {
			if (other.frenchDescription != null)
				return false;
		} else if (!frenchDescription.equals(other.frenchDescription))
			return false;
		if (frenchTitle == null) {
			if (other.frenchTitle != null)
				return false;
		} else if (!frenchTitle.equals(other.frenchTitle))
			return false;
		if (frenchValideDate == null) {
			if (other.frenchValideDate != null)
				return false;
		} else if (!frenchValideDate.equals(other.frenchValideDate))
			return false;
		if (title == null) {
			if (other.title != null)
				return false;
		} else if (!title.equals(other.title))
			return false;
		if (validDate == null) {
			if (other.validDate != null)
				return false;
		} else if (!validDate.equals(other.validDate))
			return false;
		return true;
	}

}
